package org.whl.pollution.mysql

import org.apache.spark.sql.{SaveMode, SparkSession}
import org.whl.util.spark.SparkUtil

import java.util.Properties

/**
 * @author 王浩霖
 * @version 1.0.0 2024/12/25 21:54
 */
object TemAirMysql {
    def main(args: Array[String]): Unit = {
      // 获取 SparkSession 对象
      val sparkSession: SparkSession = SparkUtil()
      package org.whl.pollution.mysql

      import org.apache.spark.sql.{SaveMode, SparkSession}
      import org.whl.util.spark.SparkUtil

      import java.util.Properties

      /**
       * @author 王浩霖
       * @version 1.0.0 2024/12/25 21:54
       */
      object TemAirMysql {
        def main(args: Array[String]): Unit = {
          // 获取 SparkSession 对象
          val sparkSession: SparkSession = SparkUtil()

          // 同步分析结果到mysql
          import sparkSession.sql

          // 每个年龄段患有心血管疾病患者人数
          val df_all = sql("select * from wanghaolin.whl_tem_air")
          val properties: Properties = SparkUtil.mysqlConnectionProperties("wanghaolin", "whl_tem_air")
          val url: String = properties.getProperty("url")
          val tableName: String = properties.getProperty("tableName")
          df_all.write.mode(SaveMode.Overwrite).jdbc(url = url, table = tableName, connectionProperties = properties)

          sparkSession.stop()
        }

      }
      package org.whl.pollution.mysql

      import org.apache.spark.sql.{SaveMode, SparkSession}
      import org.whl.util.spark.SparkUtil

      import java.util.Properties

      /**
       * @author 王浩霖
       * @version 1.0.0 2024/12/25 21:54
       */
      object TemAirMysql {
        def main(args: Array[String]): Unit = {
          // 获取 SparkSession 对象
          val sparkSession: SparkSession = SparkUtil()

          // 同步分析结果到mysql
          import sparkSession.sql

          // 每个年龄段患有心血管疾病患者人数
          val df_all = sql("select * from wanghaolin.whl_tem_air")
          val properties: Properties = SparkUtil.mysqlConnectionProperties("wanghaolin", "whl_tem_air")
          val url: String = properties.getProperty("url")
          val tableName: String = properties.getProperty("tableName")
          df_all.write.mode(SaveMode.Overwrite).jdbc(url = url, table = tableName, connectionProperties = properties)

          sparkSession.stop()
        }

      }

      // 同步分析结果到mysql
      import sparkSession.sql

      // 每个年龄段患有心血管疾病患者人数
      val df_all = sql("select * from wanghaolin.whl_tem_air")
      val properties: Properties = SparkUtil.mysqlConnectionProperties("wanghaolin", "whl_tem_air")
      val url: String = properties.getProperty("url")
      val tableName: String = properties.getProperty("tableName")
      df_all.write.mode(SaveMode.Overwrite).jdbc(url = url, table = tableName, connectionProperties = properties)

      sparkSession.stop()
    }

}
